package com.cyrus.vueboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyrus.vueboot.mapper.auth.AdminMapper;
import com.cyrus.vueboot.mapper.auth.AuthorityMapper;
import com.cyrus.vueboot.pojo.auth.Admin;
import com.cyrus.vueboot.pojo.auth.Authority;
import com.cyrus.vueboot.service.AuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/11/15
 */
@Service
public class AuthorityServiceImpl extends ServiceImpl<AuthorityMapper, Authority> implements AuthorityService {
    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private AuthorityMapper authorityMapper;

    @Override
    public IPage search(Integer page, Integer size, String key) {
        Page<Admin> adminPage = new Page(page,size);
        IPage<Admin> page1 = adminMapper.selectPage(adminPage, new QueryWrapper<Admin>().eq("isShow",1).like("authority", key));
        return page1;
    }

    @Override
    public void changeAuth(Integer authId, Integer id) {
        Authority authority = authorityMapper.selectById(authId);
        String aAuthName = authority.getAAuthName();
        Admin admin = new Admin();
        admin.setId(id);
        admin.setAuthority(aAuthName);
        adminMapper.updateById(admin);
    }
}
